<!DOCTYPE html>
<html>
<head>
  {include file="top.tpl"}

  {literal}
  <style>
	.nav-pills>li>a{background-color: #eee;}
	.pop-wrap{display: none;position: absolute;right: 0;top: 32px;padding: 15px;width: 680px;border: 1px solid #ddd;background-color: #fff;}
	.pr{position: relative;}
  </style>
  {/literal}

</head>
<body class="skin-blue">
<div class="wrapper">
  {include file="bread_crumbs.tpl"}
  	<!--引入面包屑-->
  	<section class="base-setting-wrap">
	  	<div class="row">
			<div class="col-md-12">
				<div class="box">
	                <div class="box-header with-border clearfix">
	                	<div class="nav-wrap">
	                		<ul class="nav nav-pills">
	                			<li {if $fromWarehouse=="DZWH" && $toWarehouse=="PCWH"} class='active' {/if}><a href="/backup/transfer-apply/list?from_warehouse=DZWH&to_warehouse=PCWH" class="dispatch">电子仓调至评测仓</a></li>
	                			<li {if $fromWarehouse=="DZWH" && $toWarehouse=="YB"} class='active' {/if}><a href="/backup/transfer-apply/list?from_warehouse=DZWH&to_warehouse=YB" class="dispatch">电子仓调至分销仓</a></li>
	                			<li {if $fromWarehouse=="DZWH" && $toWarehouse=="SZ"} class='active' {/if}><a href="/backup/transfer-apply/list?from_warehouse=DZWH&to_warehouse=SZ" class="dispatch">电子仓调至服装仓</a></li>
	                			<li {if $fromWarehouse=="YB" && $toWarehouse=="CNSZ"} class='active' {/if}><a href="/backup/transfer-apply/list?from_warehouse=YB&to_warehouse=CNSZ" class="dispatch">分销仓调至ebay深圳仓</a></li>
	                			<li {if $fromWarehouse=="YB" && $toWarehouse=="DZWH"} class='active' {/if}><a href="/backup/transfer-apply/list?from_warehouse=YB&to_warehouse=DZWH" class="dispatch">分销仓调至电子仓</a></li>
	                			<li {if $fromWarehouse=="YB" && $toWarehouse=="SZ"} class='active' {/if}><a href="/backup/transfer-apply/list?from_warehouse=YB&to_warehouse=SZ" class="dispatch">分销仓调至服装仓</a></li>
	                			<li {if $fromWarehouse=="SZ" && $toWarehouse=="YB"} class='active' {/if}><a href="/backup/transfer-apply/list?from_warehouse=SZ&to_warehouse=YB" class="dispatch">服装仓调至分销仓</a></li>
	                			<li {if $fromWarehouse=="SZ" && $toWarehouse=="DZWH"} class='active' {/if}><a href="/backup/transfer-apply/list?from_warehouse=SZ&to_warehouse=DZWH" class="dispatch">服装仓调至电子仓</a></li>
	                		</ul>
	                	</div>               	
	                	<div class="box-form pull-right form-group-sm">
	                		<p class="pull-right"><a href="javascript:;" class="btn btn-success btn-sm" id="js_toggleSearchBox"><i class="fa fa-search"></i><span class="pl5">搜索选项</span></a></p>
	                	</div>
	                	<div class="clearfix"></div>
						<div class="search-box" id="js_searchBox">
							<div class="row">
								<div class="col-sm-11">
									<form method="GET" class="form-inline auto-restore" id="searchForm">
										<div class="form-group-sm">	
											<p>
												<input type="hidden" name="from_warehouse" id="from_wh"/>
												<input type="hidden" name="to_warehouse" id="to_wh"/>	
												产品分类:<select id="cat_id"  data-path='{$queryParameter['catalogPath']}' style="font-size:12px;font-family:;microsoft YaHei;"></select>
												<input type="hidden" name="product_category" id="select_cat_id"/>&nbsp;	
												产品编码： <input type="text" name="goods_sn">
												审核状态：
												<select name='apply_status' id='apply_status' class="form-control ml10" name='apply_status'>
													<option value="">所有</option>
													{foreach from=$transferApply['status'] item="transferApplyStatus"}
													<option value="{$transferApplyStatus}">{$transferApplyStatus}</option>
													{/foreach}
												</select>
												<br/><br/>
										         需求时间:
												<input type="text" class="form-control js_datePicker date_start" name="min_apply_date" value="" placeholder="开始时间">-
												<input type="text" class="form-control js_datePicker date_end" name="max_apply_date" value="" placeholder="结束时间">
												需调拨数量：
			                                    <select name='apply_quantity_operator' id='apply_status' class="form-control ml10">
													<option value="0">所有</option>
													<option value="1">大于等于</option>
													<option value="2">小于</option>
												</select>
												<input type="text" class="form-control" name='apply_quantity' value="">
												<button type="button" class="btn btn-primary btn-sm" id="search_button">立即搜索</button>											
											</p>							
										</div>
									</form>
								</div>
								<div class="col-sm-1">
									<div class="pull-right pr">
										<a href="javascript:;" id="start_pop" class="btn btn-primary btn-sm">自动审核规则设置</a>
										<div class="pop-wrap">
											<form class="form-inline" method="POST" action="" id="auto-check-rule_form">
												<div class="form-group-sm mb20">
													<label class="control-label">调拨列表页名称：</label>
													<select  class="form-control rule-belong-warehouse">
													    {if $fromWarehouse=="DZWH" && $toWarehouse=="YB"}
														  <option value="0" data-from-warehouse="DZWH" data-to-warehouse="YB">电子仓调至分销仓</option>
														{/if}
														{if $fromWarehouse=="DZWH" && $toWarehouse=="SZ"}
														<option value="1" data-from-warehouse="DZWH" data-to-warehouse="SZ">电子仓调至服装仓</option>
														{/if}
														{if $fromWarehouse=="DZWH" && $toWarehouse=="PCWH"}
														<option value="2" data-from-warehouse="DZWH" data-to-warehouse="PCWH">电子仓调至评测仓</option>
														{/if}
														{if $fromWarehouse=="YB" && $toWarehouse=="CNSZ"}
														<option value="3" data-from-warehouse="YB" data-to-warehouse="CNSZ">分销仓调至ebay深圳仓</option>
														{/if}
														{if $fromWarehouse=="YB" && $toWarehouse=="DZWH"}
														<option value="4" data-from-warehouse="YB" data-to-warehouse="DZWH">分销仓调至电子仓</option>
														{/if}
														{if $fromWarehouse=="YB" && $toWarehouse=="SZ"}
														<option value="5" data-from-warehouse="YB" data-to-warehouse="SZ">分销仓调至服装仓</option>
														{/if}
														{if $fromWarehouse=="SZ" && $toWarehouse=="YB"}
														<option value="6" data-from-warehouse="SZ" data-to-warehouse="YB">服装仓调至分销仓</option>
														{/if}
														{if $fromWarehouse=="SZ" && $toWarehouse=="DZWH"}
														<option value="7" data-from-warehouse="SZ" data-to-warehouse="DZWH">服装仓调至电子仓</option>
														{/if}
													</select>
													<input type="hidden" class="form-control" name="from_warehouse" id="check_rule_from_warehouse" >
													<input type="hidden" class="form-control" name="to_warehouse" id="check_rule_to_warehouse">
												</div>
											
												<div class="form-group-sm mb20">
													<label class="control-label">生命周期：成长期</label>
										
													<input type="hidden" class="form-control" name="condition_type[]" value="lifeCycle">

								                    <input type="hidden" class="form-control" name="condition_operator[]" value="eq">

                                                    <input type="hidden" class="form-control" name="condition_min_value[]" value="0">
													<input type="hidden" class="form-control" name="condition_max_value[]" value="0">
													<input type="hidden" class="form-control" name="condition_eq_value[]"  value="成长期">
																									
													<label class="control-label ml20">最终调拨数量：</label>
													<input type="text" class="form-control" name="check_quantity_lower[]" value="{$autoCheckLifeCycleRule['成长期']['check_quantity_lower']|default:''}">-
													<input type="text" class="ml10 form-control" name="check_quantity_upper[]" value="{$autoCheckLifeCycleRule['成长期']['check_quantity_upper']|default:''}">
												</div>

												<div class="form-group-sm mb20">
													<label class="control-label">生命周期：成熟期</label>
												
												    <input type="hidden" class="form-control" name="condition_type[]" value="lifeCycle">	

								                    <input type="hidden" class="form-control" name="condition_operator[]" value="eq">	

		                                             <input type="hidden" class="form-control" name="condition_min_value[]" value="0">
													<input type="hidden" class="form-control" name="condition_max_value[]" value="0">
													<input type="hidden" class="form-control" name="condition_eq_value[]"  value="成熟期">

													<label class="control-label ml20">最终调拨数量：</label>
								                     <input type="text" class="form-control" name="check_quantity_lower[]" value="{$autoCheckLifeCycleRule['成熟期']['check_quantity_lower']|default:''}">-
													<input type="text" class="ml10 form-control" name="check_quantity_upper[]" value="{$autoCheckLifeCycleRule['成熟期']['check_quantity_upper']|default:''}">
												</div>
												<div class="form-group-sm mb20">
													<label class="control-label">生命周期：衰败期</label>
											
												     <input type="hidden" class="form-control" name="condition_type[]" value="lifeCycle">	

								                    <input type="hidden" class="form-control" name="condition_operator[]" value="eq">	

		                                            <input type="hidden" class="form-control" name="condition_min_value[]" value="0">
													<input type="hidden" class="form-control" name="condition_max_value[]" value="0">
													<input type="hidden" class="form-control" name="condition_eq_value[]"  value="衰败期">

													<label class="control-label ml20">最终调拨数量：</label>
			                                     	<input type="text" class="form-control" name="check_quantity_lower[]" value="{$autoCheckLifeCycleRule['衰败期']['check_quantity_lower']|default:''}">-
													<input type="text" class="ml10 form-control" name="check_quantity_upper[]" value="{$autoCheckLifeCycleRule['衰败期']['check_quantity_upper']|default:''}">
												</div>
												<div class="form-group-sm mb20">
													<label class="control-label">生命周期：其他时期</label>
									
											        <input type="hidden" class="form-control" name="condition_type[]" value="lifeCycle">	
								                    <input type="hidden" class="form-control" name="condition_operator[]" value="eq">

		                                            <input type="hidden" class="form-control" name="condition_min_value[]" value="0">
													<input type="hidden" class="form-control" name="condition_max_value[]" value="0">
													<input type="hidden" class="form-control" name="condition_eq_value[]"  value="其它时期">

													<label class="control-label ml20">最终调拨数量：</label>
						                            <input type="text" class="form-control" name="check_quantity_lower[]" value="{$autoCheckLifeCycleRule['其它时期']['check_quantity_lower']|default:''}">-
													<input type="text" class="ml10 form-control" name="check_quantity_upper[]" value="{$autoCheckLifeCycleRule['其它时期']['check_quantity_upper']|default:''}">
												</div>
												<div class="form-group-sm">
													<input type="button" id='save-check-apply-rule' class="btn btn-default btn-sm ml50 mr50" value="确定" >
													<input type="button" id="end_pop" class="btn btn-default btn-sm" value="取消">
												</div>
											</form>
										</div>
									</div>
								</div>
							</div>
						</div>
	                </div>
	                <!-- /.box-header -->
	                <div class="box-body">
	                  <table class="table table-bordered table-striped table-hover">
	                  	<thead>
	                    <tr>
	                      <th ></th>
	                      <th >产品编码</th>
	                      <th >产品图片</th>
	                      <th >产品名称</th>
	                      <th >可用库存</th>
	                      <th >前7天销量</th>
	                      <th >前15天销量</th>
	                      <th >前30天销量</th>
	                      <th >需求数量A</th>
	                      <th >需求数量B</th>
	                      <th >需求数量C</th>
	                      <th >采购员</th>
	                      <th >产品状态</th>
	                      <th >调入仓</th>
	                      <th >调出仓</th>
	                      <th >需调拨数量</th>
	                      <th >可调拨数量</th>
	                      <th >数据产生时间</th>
	                      <th >审核状态</th>
	                      <th >已审核调拨数量</th>
	                      <th >出库数量</th>
	                      <th >上次审核结果</th>
	                    </tr>
	                    </thead>	                    
	                    <tbody>
	                   	{foreach from=$applyList item="apply"}
	                   	<tr>	 						
		                  <td ><input type="checkbox" name="apply_checkitem" class="apply_checkitem" value="{$apply['stock_transfer_apply_id']}"></td>
	                      <td >{$apply['goods_sn']}</td>
	                      <td ><img src="{$pdmDomain}{$apply['thumb_url']}"></td>
	                      <td >{$apply['product_name']}</td>
	                      <td >{$apply['availableStock']}</td>
	                      <td >{$apply['the7DaySales']}</td>
	                      <td >{$apply['the15DaySales']}</td>
	                      <td >{$apply['the30DaySales']}</td>
	                      <td >{$apply['before_transfer_a_story_quantity']}</td>
	                      <td >{$apply['before_transfer_b_story_quantity']}</td>
	                      <td >{$apply['before_transfer_c_story_quantity']}</td>
	                      <td >{$apply['purchaser']}</td>
	                      <td >{$transferApply['productStatus'][$apply['product_status']]}</td>
	                      <td >{$toWarehouseName}</td>
	                      <td >{$fromWarehouseName}</td>
	                      <td >{$apply['apply_quantity']}</td>
	                      <td >{$apply['can_transfer_quantity']}</td>
	                      <td >{$apply['create_date']}</td>
	                      <td >{$apply['status']}</td>
	                      <td >{$apply['check_pass_quantity']}</td>
	                      <td >{$apply['warehouse_out_quantity']}</td>
	                      <td >{$apply['lastCheckResult']}</td>								
						</tr>		
	                   {/foreach}
	                    </tbody>			                 
	              	</table>
	                </div>
	                <!-- .box-body -->
	                <div class="pl10">
		                <input type="checkbox" name="apply_checkall" class="apply_checkall">
		                <select id="checkOperationType">
		                    <option value="0">请选择</option>
		                	<option value="1">审核通过</option>
		                	<option value="2">审核驳回</option>
		                </select>
		                <input type="button" id="betchCheckApply" value="确定">
	                </div>
	                <div class="box-footer text-center clearfix">
					{$page_link}
	                </div>
	              </div>
			</div>
		</div>
	</section>
 </div>
{include file='foot.tpl'}
<script type="text/javascript">
{literal}

//全选反选
$.fn.check({checkall_name: "apply_checkall", checkbox_name:"apply_checkitem"});

//审核
$("#transferApplyCheckBut").bind("click",function(){
	var checkedApplyId="";
	$.each($(".apply_checkitm").attr("checked", true),function(checkedApply){
		alert(checkedApply);
        checkedApplyId+=$(checkedApply).val();
	});
	alert(checkedApplyId);
});

$("#betchCheckApply").bind("click", function() {
	var ids = [];
	$("input[name=apply_checkitem]").each(function(index,node){
		if ($(node).prop('checked')) {
			ids.push($(node).val());
		};
	})
	if (ids.length < 1) {
		layer.alert("请选择要审核或者驳回的申请！");
		return false;
	};
    
    var checkOperationType=$("#checkOperationType").val();
    if(checkOperationType==0){
    	layer.alert("请选择操作类型！");
		return false;
    }
    

    var operationName="";
    var checkUrl="";
    if(checkOperationType==1){
        operationName="审核通过";
        checkUrl="/backup/transfer-apply/agree"
    }else if(checkOperationType==2){
        operationName="审核驳回";
        checkUrl="/backup/transfer-apply/reject";
    }else{
    	return false;
    }

	layer.confirm("确定要"+operationName+"这些调拨申请？", function(){
		$.post(checkUrl, {applyId:ids.join(',')}, function(res) {
			if(res.status == true){
                layer.alert(res.msg);
                location.reload();
            }else if(res.status == false){
                layer.alert(res.msg);
            }
		}, 'json');
	});
})

//产品分类
var catalogPath=$("#cat_id").attr("data-path");
var opts = {
	ajax: '/widget/category/getcat',
	selClass:'form-control inline',
	selStyle: 'font-size:12px;font-family:;microsoft YaHei;',
	autoLink : false,
	defVal:catalogPath.split(','),
	head: '请选择产品分类',
	select:  '#cat_id',
};
var linkageSel = new LinkageSel(opts);
$('#search_button').click(function(){
	var v = linkageSel.getSelectedValue();
	$('#select_cat_id').val(v);
	$("#searchForm").submit();
});

$(function(){
	$('.date_start').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	}).on('changeDate', function(ev){
        $(".date_end").val("").datetimepicker('setStartDate',$(this).val());
    });
    $('.date_end').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	});
})

	/*需求调拨*/
	function getQueryStr(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return r[2];
        }
        return null;
    }

    var from_warehouse = getQueryStr("from_warehouse"),
    	to_warehouse = getQueryStr("to_warehouse"),
		str_from = 'from_warehouse='+from_warehouse,
		str_to = 'to_warehouse='+to_warehouse;

	//调拨选择按钮加active标记
	$(".dispatch").each(function(i,v){			
		var this_href =$(v).attr("href");

		if(this_href.match(str_from) != null &&　this_href.match(str_to) != null){
			$(v).parent().addClass("active");
		}
	});
	
	//审核规则设置
	$("#start_pop").on("click",function(){
		$(".pop-wrap").fadeToggle();
	});
	$("#end_pop").on("click",function(){
		$(".pop-wrap").fadeOut();
	});

   //调拨申请自动审核规则保存
   $("#save-check-apply-rule").bind("click",function(){
   	 var from_warehouse=$(".rule-belong-warehouse option:selected").data('from-warehouse');
   	 var to_warehouse=$(".rule-belong-warehouse option:selected").data('to-warehouse');

   	 $("#check_rule_from_warehouse").val(from_warehouse);
   	 $("#check_rule_to_warehouse").val(to_warehouse);

   	$.ajax({
		   type: "POST",
		   url: "/backup/transfer-apply/save-check-rule",
		   data: $("#auto-check-rule_form").serialize(),
		   success: function(result){
		     alert( result.msg );
		   }
    });
  
   })
{/literal}
</script>
<script src="{$js.url}form_helper.js"></script>
</body>
</html>